<?php
/**
 * Created by PhpStorm.
 * User: 94004
 * Date: 2017/12/29
 * Time: 16:15
 */
header("Content-Type:text/html;charset=utf-8;");
require_once "../util/db_helper.php";
$id = $_POST["id"];
$old = $_POST["old"];
$newPwd = $_POST["newPwd"];
$sql = " SELECT u.password FROM  users u WHERE id = {$id} ";
$res = query($sql);
$arr = array("code" => 101, "msg" => "操作失败");
if ($res) {
    if ($res[0]["password"] == $old) {
        $resPwd = updatePassword("users", $newPwd, $id);
        if ($resPwd) {
            $arr["code"] = 100;
            $arr["msg"] = "修改密码成功,请重新登录";
        }
    }
    else {
        $arr["msg"] = "旧密码不正确，请重新输入";
    }
}
echo json_encode($arr, JSON_UNESCAPED_UNICODE);
?>